#include "setting.h"
#include "ui_setting.h"
bool state_fullscreen = false;
setting::setting(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::setting)
{


    ui->setupUi(this);

    setWindowFlag(Qt::FramelessWindowHint);
    setStyleSheet("background-color: rgba(220,220,220, 128); border-radius: 10px; color:rgb(0,0,0);");
    QSlider* slider = this->findChild<QSlider*>("horizontalSlider");
    slider->setValue(100);
    connect(slider, &QSlider::valueChanged, [this](int value) {
        //根据滑动条的值设置窗口的透明度（假设范围是 0-100）

       opacity = (float)value / 100;

        if(opacity >0.2){
            setWindowOpacity(opacity);
            ui->label_2->setText(QString("%1%").arg(value+1));
        }


    });
    if(state_fullscreen){
        ui->checkBox->setChecked(true);
    }else {
        ui->checkBox->setChecked(false);
    }
}

setting::~setting()
{
    delete ui;
}

void setting::on_pushButton_clicked()
{
//    if(ui->checkBox->isChecked()){

//    }
    state_fullscreen = ui->checkBox->isChecked();

    connect(ui->pushButton, &QPushButton::clicked, this, &setting::close);

//    close();
}

//void setting::on_horizontalSlider_rangeChanged(int min, int max)
//{

//}

void setting::on_horizontalSlider_sliderReleased()
{
    QSlider* slider = this->findChild<QSlider*>("horizontalSlider");


        //根据滑动条的值设置窗口的透明度（假设范围是 0-100）
        int value = slider->value();
        float opacity = (float)value / 100;

        if(opacity <= 0.1) {
            slider->setValue(20);
            QMessageBox::critical(this,
            tr("透明度太低看不见哦"
               ),
            tr("透明度太低看不见哦\n")
            );
        }
}
